
package botlab.control;

import botlab.Game;
import botlab.gui.Notifier;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.PhysicsCollisionEvent;
import com.jme3.bullet.collision.PhysicsCollisionListener;
import com.jme3.math.Vector3f;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control;

/**
 *
 * @author Quentin
 */
public class LooseCollisionControl extends BaseControl implements PhysicsCollisionListener
{

    public LooseCollisionControl()
    {
        Game.getApp().getStateManager().getState(BulletAppState.class).getPhysicsSpace().addCollisionListener(
                this);
    }
    
    public void collision(PhysicsCollisionEvent event)
    {

        if (spatial!=null && event!=null && (spatial.getName().equals(event.getNodeA().getName()) 
                || spatial.getName().equals(event.getNodeB().getName())))
        {
            //Action to do when collision is detected
            Game.getApp().loose();
            java.awt.EventQueue.invokeLater(new Runnable()
            {
                public void run()
                {
                    Notifier.getInstance().enterState("collision");
                }
            });

        }

    }

    @Override
    protected void controlUpdate(float tpf)
    {
//         MainAppState.getText().setText("controlUpdate");
    }

    @Override
    public Control cloneForSpatial(Spatial spatial)
    {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
